import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { BgItem } from "../common/BgItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { IntegralShopConfig } from "../../resource/IntegralShopConfig";
import { BuyAlert } from "../pet/BuyAlert";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { ItemData } from "../../resource/info/ItemData";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { Language } from "../../../../extend/language/Language";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { TIntegralShopItemNew } from "../../../../Message/Db/Tables/TIntegralShopItemNew";
import { ImagesConst } from "../../resource/ImagesConst";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class InExShopItem
    
    export  class InExShopItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.createChildren();
            this.addListeners();
            this._btnPrice.textField.defaultTextFormat = GlobalStyle.textFormat6;
            this._btnPrice.setStyle("textFormat", GlobalStyle.textFormat6);
            this._btnPrice.drawNow();
            (this._btnPrice.getChildAt(1) as Object /* flash.text.TextField */).filters = [FilterConst.nameGlowFilter];
            addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._bgItem) 
            {
                this._bgItem.filters = [FilterConst.itemChooseFilter];
            }
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._bgItem) 
            {
                this._bgItem.filters = [];
            }
            return;
        }

        protected createChildren(): void
        {
            this._btnPrice = ObjCreate.createGLoadedButton(ResFileConst.InExbtn, 7, 38, 45, 33, this);
            this._bgItem = new BgItem();
            this._bgItem.x = 9;
            this.addChild(this._bgItem);
            this.createUnitIcon();
            return;
        }

        public updatePriceBtnStyle(arg1: string, arg2: int, arg3: int): void
        {
            if (this._btnPrice) 
            {
                this._btnPrice.styleName = arg1;
                this._btnPrice.width = arg2;
                this._btnPrice.height = arg3;
                if (arg2 > 50) 
                {
                    this._btnPrice.x = -10;
                }
                else 
                {
                    this._btnPrice.x = 7;
                }
                if (arg3 > 40) 
                {
                    this._btnPrice.y = 25;
                }
                else 
                {
                    this._btnPrice.y = 38;
                }
            }
            return;
        }

        protected createUnitIcon(arg1: int=43, arg2: int=45): void
        {
            this._unitIconBitmap = new Object /* flash.display.Bitmap */();
            this._unitIconBitmap.x = arg1;
            this._unitIconBitmap.y = arg2;
            this.addChild(this._unitIconBitmap);
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._unitIconBitmap.bitmapData = GlobalClass.getBitmapData(this._unitIcon);
            return;
        }

        protected addListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=false;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            if (this._shopItem) 
            {
                loc1 = IntegralShopConfig.instance.getUnitByShopId(this._shopItem.shopId);
                loc2 = this._shopItem.price;
                if (!(loc3 = BuyAlert.checkMoney(loc1, loc2))) 
                {
                    return;
                }
                loc4 = ItemsUtil.getItemName(new ItemData(this._shopItem.itemCode));
                loc5 = GameDefConfig.instance.getEPrictUnitName(loc1);
                loc6 = Language.getStringByParam(35047, loc2, loc5, loc4);
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.IntegralExchangesShopNotTip, this.requestBuy, loc6, null, Alert.OK | Alert.CANCEL);
            }
            return;
        }

        protected requestBuy(): void
        {
            if (this._shopItem) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.IntegralExchangeBuyItem, {"shopId": this._shopItem.shopId, "itemCode": this._shopItem.itemCode, "amount": 1}));
            }
            return;
        }

        protected updateView(): void
        {
            if (this._shopItem) 
            {
                this._bgItem.setItemCode(this._shopItem.itemCode);
                this._btnPrice.label = this._shopItem.price.toString();
                this.updateUnitIcon();
            }
            else 
            {
                this._bgItem.setItemCode(0);
                this._btnPrice.label = "";
            }
            return;
        }

        protected updateUnitIcon(): void
        {
            this._unitIcon = this.getUnitIcon(this._shopItem.shopId);
            LoaderHelp.addResCallBack(ResFileConst.IntegralShop, this.onLoadedHandler);
            return;
        }

        public updateData(arg1: TIntegralShopItemNew): void
        {
            this._shopItem = arg1;
            this.updateView();
            return;
        }

        /* internal  */getUnitIcon(arg1: int): string
        {
            var loc1=ImagesConst.ISUnitIcon0;
            var loc2=IntegralShopConfig.instance.getUnitByShopId(arg1);
            if (loc2 != EPrictUnit._EPriceUnitIntegralTwo) 
            {
                if (loc2 == EPrictUnit._EPriceUnitIntegralThree) 
                {
                    loc1 = ImagesConst.ISUnitIcon2;
                }
            }
            else 
            {
                loc1 = ImagesConst.ISUnitIcon1;
            }
            return loc1;
        }

        protected /* var */_btnPrice: GLoadedButton;

        /* internal */ /* var */_bgItem: BgItem;

        protected /* var */_unitIconBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_shopItem: TIntegralShopItemNew;

        /* internal */ /* var */_unitIcon: string;
    }
